#-*- coding: utf-8 -*-

import threading

lock = threading.Lock()

#выполнение функции в отдельном потоке
def create_thread(name='', daemon=False):
    def decor(func):
        def wrap(*args, **kwargs):
            with lock:
                t = threading.Thread(target=func, args=args, kwargs=kwargs)
                if name: t.setName(name)
                if daemon: t.setDaemon(True)
                t.start()
        return wrap
    return decor

def run_thread(func, name='', daemon=False, args=(), kwargs = None):
    t = threading.Thread(target=func, args=args, kwargs=kwargs)
    if name: t.setName(name)
    if daemon: t.setDaemon(True)
    t.start()

